home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK2.toast / Development Kits (Disc 2) / QuickDraw GX / Programming Stuff / GX Libraries / CollectionLibrary.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-16  |  7.3 KB  |  283 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CollectionLibrary.c
  3.  
  4.     Contains:    Handy printing collection sample routines.
  5.  
  6.     Written by:    Dave Hersey
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                 Dave Hersey
  13.  
  14.         Other Contact:        Ron Voss
  15.  
  16.         Technology:         QuickDraw GX
  17.  
  18.     Change History (most recent first):
  19.  
  20.          <1>      6/6/95    DH        First checked in.
  21. */
  22.  
  23. #include "CollectionLibrary.h"
  24.  
  25. #define kCategoryMask 0x0000FFFF
  26.  
  27.  
  28. /****************************************************************************************
  29.  
  30.                             SetCollectionItemCategory
  31.                             
  32.     function :
  33.                     Assigns a tag/ID pair to a category in the given collection.
  34.     parameters :
  35.                     the collection, the tag, the ID, and the category
  36.  
  37. ****************************************************************************************/
  38. OSErr SetCollectionItemCategory (    Collection theCollection,
  39.                                     CollectionTag tag,
  40.                                     long tagID,
  41.                                     gxCollectionCategory theCategory)
  42. {
  43.     OSErr     anErr;
  44.  
  45.     
  46. // Set the item's attributes to be the provided category, ORed with the existing bits.
  47.  
  48.     anErr = SetCollectionItemInfo(    theCollection,
  49.                                     tag,
  50.                                     tagID,
  51.                                     kCategoryMask,
  52.                                     (long) theCategory);
  53.                                     
  54.     return (anErr);
  55. }
  56. /****************************************************************************************
  57.  
  58.                             GetCollectionItemCategory
  59.                             
  60.     function :
  61.                     Returns the category assigned to the tag/ID pair 
  62.                     in the given collection.
  63.     parameters :
  64.                 
  65. ****************************************************************************************/
  66. OSErr GetCollectionItemCategory( Collection         theCollection,
  67.                                    CollectionTag         tag,
  68.                                  long                tagID,
  69.                                  gxCollectionCategory *theCategory)
  70. {
  71.     OSErr     anErr;
  72.     long    attributes;
  73.     
  74.     
  75. // Get the item's attributes in the provided category. Then get the category bits
  76.  
  77.     anErr = GetCollectionItemInfo(    theCollection,
  78.                                     tag,
  79.                                     tagID,
  80.                                     dontWantIndex,
  81.                                     dontWantSize,
  82.                                     &attributes);
  83.                                     
  84.     *theCategory = attributes & kCategoryMask;
  85.     
  86.     return (anErr);
  87. }
  88.  
  89.  
  90. /****************************************************************************************
  91.  
  92.                             RemoveCollectionCategory
  93.                             
  94.     function :
  95.                     Removes a category from the given collection
  96.     parameters :
  97.                 
  98. ****************************************************************************************/
  99. OSErr RemoveCollectionCategory( Collection             theCollection,
  100.                                   gxCollectionCategory    theCategory)
  101. {
  102.  
  103. // Yank all the items which have those bits set.
  104.  
  105.     PurgeCollection(theCollection, theCategory, theCategory);
  106.  
  107.     return (noErr);
  108. }
  109.  
  110. /****************************************************************************************
  111.  
  112.                             GetCollectionItemLock
  113.                             
  114.     function :
  115.                     Returns true if the item is locked
  116.     parameters :
  117.                     the collection, tag, and ID
  118.                     
  119.     returns:        
  120.                     OSErrs
  121.                     *isLocked contains the lock state
  122.                 
  123. ****************************************************************************************/
  124. OSErr GetCollectionItemLock( Collection     theCollection,
  125.                              CollectionTag     tag,
  126.                              long            tagID,
  127.                              Boolean        *isLocked)
  128. {
  129.     OSErr     anErr;
  130.     long    attributes;
  131.     
  132. // Get the attributes of the item in question
  133.  
  134.     anErr = GetCollectionItemInfo(    theCollection,
  135.                                     tag,
  136.                                     tagID,
  137.                                     nil,            // don't want the index
  138.                                     nil,            // don't want the size
  139.                                     &attributes);
  140.  
  141.  
  142. // Then determine if "locked" is one of the attributes.
  143.  
  144.     *isLocked = ((attributes & collectionLockMask) == collectionLockMask);
  145.  
  146.     return (anErr);
  147. }
  148. /****************************************************************************************
  149.  
  150.                             SetCollectionItemLock
  151.                             
  152.     function :
  153.                     Locks the given item
  154.     parameters :
  155.                 
  156. ****************************************************************************************/
  157. OSErr SetCollectionItemLock( Collection     theCollection,
  158.                              CollectionTag     tag,
  159.                              long            tagID,
  160.                              Boolean        lockIt)
  161. {
  162.     OSErr     anErr;
  163.     long    lockState;
  164.     
  165.     
  166. // Set the bit according to lockIt.
  167.  
  168.     if (lockIt)
  169.         lockState = collectionLockMask;
  170.     else
  171.         lockState = 0;
  172.         
  173.     anErr = SetCollectionItemInfo(    theCollection,
  174.                                     tag,
  175.                                     tagID,
  176.                                     collectionLockMask,
  177.                                     lockState);
  178.  
  179.     return (anErr);
  180. }
  181.  
  182.  
  183. /****************************************************************************************
  184.  
  185.                             AddJobItem
  186.                             
  187.     function :
  188.                     Adds an item to a job collection.
  189.     parameters :
  190.                     the collection, the tag, the ID, and the category
  191.  
  192. ****************************************************************************************/
  193. OSErr AddJobItem (gxJob aJob, CollectionTag tag, long id, long itemSize, void *itemData)
  194. {
  195.     if (!aJob) return paramErr;
  196.     return AddCollectionItem(GXGetJobCollection(aJob), tag, id, itemSize, itemData);
  197. }
  198.  
  199.  
  200. /****************************************************************************************
  201.  
  202.                             AddFormatItem
  203.                             
  204.     function :
  205.                     Adds an item to a format collection.
  206.     parameters :
  207.                     the collection, the tag, the ID, and the category
  208.  
  209. ****************************************************************************************/
  210. OSErr AddFormatItem (gxFormat aFormat, CollectionTag tag, long id, long itemSize, void *itemData)
  211. {
  212.     if (!aFormat) return paramErr;
  213.     return AddCollectionItem(GXGetFormatCollection(aFormat), tag, id, itemSize, itemData);
  214. }
  215.  
  216.  
  217.  
  218. /****************************************************************************************
  219.  
  220.                             AddVolatileJobItem
  221.                             
  222.     function :
  223.                     Adds a purgeable item to a job collection.
  224.                     When called by driver, will auotmatically
  225.                     set the correct bits to make the item purgeable for that driver.
  226.     parameters :
  227.                     the collection, the tag, the ID, and the category
  228.  
  229. ****************************************************************************************/
  230. OSErr AddVolatileJobItem (gxJob aJob, CollectionTag tag, long id, long itemSize, void *itemData)
  231. {
  232.     OSErr anErr;
  233.     Collection jobCollection;
  234.     
  235.     if (!aJob) return paramErr;
  236.     jobCollection = GXGetJobCollection(aJob);
  237.     
  238.     anErr = AddCollectionItem(jobCollection, tag, id, itemSize, itemData);
  239.     
  240.     if (!anErr) {
  241.         gxCollectionCategory category = (GXGetJobPrinter(aJob) == GXGetJobOutputPrinter(aJob))
  242.                                     ? gxVolatileOutputDriverCategory
  243.                                     : gxVolatileFormattingDriverCategory;
  244.                                     
  245.         (void) SetCollectionItemCategory(jobCollection, tag, id, category);
  246.     }
  247.     return anErr;
  248. }
  249.  
  250.  
  251. /****************************************************************************************
  252.  
  253.                             AddVolatileFormatItem
  254.                             
  255.     function :
  256.                     Adds a purgeable item to a format collection.
  257.                     When called by driver, will auotmatically
  258.                     set the correct bits to make the item purgeable for that driver.
  259.     parameters :
  260.                     the collection, the tag, the ID, and the category
  261.  
  262. ****************************************************************************************/
  263. OSErr AddVolatileFormatItem (gxFormat aFormat, CollectionTag tag, long id, long itemSize, void *itemData)
  264. {
  265.     OSErr anErr;
  266.     Collection formatCollection;
  267.     
  268.     if (!aFormat) return paramErr;
  269.     formatCollection = GXGetFormatCollection(aFormat);
  270.     
  271.     anErr = AddCollectionItem(formatCollection, tag, id, itemSize, itemData);
  272.     
  273.     if (!anErr) {
  274.         gxJob aJob = GXGetFormatJob(aFormat);
  275.         gxCollectionCategory category = (GXGetJobPrinter(aJob) == GXGetJobOutputPrinter(aJob))
  276.                                     ? gxVolatileOutputDriverCategory
  277.                                     :gxVolatileFormattingDriverCategory;
  278.                                     
  279.         (void) SetCollectionItemCategory(formatCollection, tag, id, category);
  280.     }
  281.     return anErr;
  282. }
  283.